package com.wfk.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wfk.entity.MoneyDetails;
import com.wfk.mapper.MoneyDetailsMapper;
import com.wfk.service.IMoneyDetailsService;
import com.wfk.utils.BasePage;
import com.wfk.utils.ValidateUtil;

/**
 * <p>
 * 用户金额明细表 服务实现类
 * </p>
 *
 * @since 2019-01-07
 */
@Service
public class MoneyDetailsServiceImpl extends ServiceImpl<MoneyDetailsMapper, MoneyDetails> implements IMoneyDetailsService {
	@Autowired
	private MoneyDetailsMapper moneyDetailsMapper;
	@Override
	public BasePage<MoneyDetails> listPage(MoneyDetails details, BasePage<MoneyDetails> page) {
		QueryWrapper<MoneyDetails> queryWrapper = new QueryWrapper<MoneyDetails>();
		if (ValidateUtil.date(details.getStart())) {
			queryWrapper.ge("createtime",details.getStart()+"00:00");
		}
		if (ValidateUtil.date(details.getEnd())) {
			queryWrapper.ge("createtime",details.getEnd()+" 23:59");
		}
		if(ValidateUtil.empty(details.getPaycode())){
			queryWrapper.eq("paycode", details.getPaycode());
		}
		if(!ValidateUtil.objEmpty(details.getTypeid())){
			queryWrapper.eq("typeid", details.getTypeid());
		}
		if(details.getCid()!=null) {
			queryWrapper.eq("cid",details.getCid());
		}
		queryWrapper.orderByDesc("id");
		if(page.isPage()) {
			super.page(page,queryWrapper);
		}else {
			List<MoneyDetails> list = super.list(queryWrapper);
			page.setRecords(list);
		}
		return page;
	}

	@Override
	public BigDecimal typeMoney(Integer type, Date time) {
		return moneyDetailsMapper.typeMoney(type, time);
	}

}
